<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/header.jsp" %>
<%@ include file="/common/datatables.jsp" %>

<script type="text/javascript">	
var scripts = [null, null];
$('.page-content-area').ace_ajax('loadScripts', scripts, function() {
	$.widget("ui.dialog", $.extend({}, $.ui.dialog.prototype, {
		_title: function(title) {
			var $title = this.options.title || '&nbsp;'
			if( ("title_html" in this.options) && this.options.title_html == true )
				title.html($title);
			else title.text($title);
		}
	}));  

//字典类型新增
$('#dictDetailIframe').dialog({
	hide:false,
	autoOpen:false,
	width: 650,
	height:400,
	modal:true,
	//bgiframe:true,
	title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-cog green'></i>&nbsp; 编辑字典类型</h4></div>",
	title_html: true,
	open:function(event,ui){
		var dictBtnFlag = $(this).data("dictBtnFlag");
		//alert("dictBtnFlag:"+dictBtnFlag);
		if(dictBtnFlag=="add"){
			$("#btnAModify").hide();
    		$("#btnADelete").hide();
    		$("#btnASave").show();
    		$("#btnACancle").hide();
		}else if(dictBtnFlag=="show"){
			$("#btnAModify").show();
        	$("#btnADelete").hide();
        	$("#btnASave").hide();
        	$("#btnACancle").hide();
		}
	},
	buttons: [
	            
				{
					id: "btnAModify",
					html: "<i class='ace-icon fa fa-pencil-square-o bigger-110'></i>&nbsp; 修改",
					"class" : "btn btn-primary btn-minier",
					click: function() {
						modify();
					}
				},
				{
					id: "btnASave",
					html: "<i class='ace-icon fa fa-floppy-o bigger-110'></i>&nbsp; 保存",
					"class" : "btn btn-success btn-minier",
					click: function() {
						save();
						$("#entryDetailInfo").empty();
					}
				},
				{
					id: "btnADelete",
					html: "<i class='ace-icon fa fa-trash-o bigger-110'></i>&nbsp; 删除",
					"class" : "btn btn-danger btn-minier",
					click: function() {
						remove();
					}
				},
				{
					id: "btnACancle",
					html: "<i class='ace-icon fa fa-undo bigger-110'></i>&nbsp; 取消",
					"class" : "btn btn-warning btn-minier",
					click: function() {
						cancle();
					}
				},												
				{
					id: "btnAClose",
					html: "<i class='ace-icon fa fa-times bigger-110'></i>&nbsp; 关闭",
					"class" : "btn btn-minier",
					click: function() {
						$(this).dialog("close");
					}
				}				
			]
		});

		var dictTable;
		dictTable = $("#dictInfoLists").dataTable({
			"bProcessing": true,
			"bServerSide": true,
			"bDestroy":true,
			"bSort": false,
			"bFilter": false,
			"destroy": true,//解决 Cannot reinitialise DataTable的问题
			"oLanguage":oLanguage,
			"bAutoWidth": false,
			"sPaginationType": "full_numbers",
			"sAjaxSource": "${ctx}/dict/listData?temp="+new Date().getTime(),
			"fnServerParams": function ( aoData ) {
				aoData.push( { "name": "dictType", "value": "${dictType.dictType}" } );
			
				aoData.push( { "name": "dictDesc", "value": "${dictType.dictDesc}" } );
			},
			"fnServerData": fnDataTablesPipeline,
			"fnInitComplete": function(param){
				$("#dictInfoLists_filter").append("<button class=\"btn btn-sm btn-purple btn-right\" type=\"button\" onclick=\"addDictFuc()\">"+
						"<i class=\"ace-icon fa fa-plus-square bigger-110\"></i>"+
							"新增"+
						"</button>");
			},
	        "fnDrawCallback" : function(param) {			
	        	$('#dictInfoLists tbody td').each(function(index){
				    $this = $(this);
				    $this.attr("class","td-overflow");
				    $this.attr("style","width:150px;");
				    var titleVal = $this.text();
				    if (titleVal != '') {
				      $this.attr('title', titleVal);
				    }
				});
				
			}, 
			"aoColumnDefs": [
                { "bSearchable": false, "bVisible": false }
            ]
		});
		
		
		$('#dictInfoLists').on('click', 'tbody tr' , function(){
			var active_class = 'success';
			var $row = $(this).closest('tr');	
			if ($row.hasClass(active_class) == false) {
				dictTable.$('tr.' + active_class).removeClass(active_class);
				$row.addClass(active_class);				
			}
			var aData = dictTable.fnGetData(this); 
			var param = {"dictType":aData[0]};
			$("#entryDetailInfo").load("${ctx}/dict/entryList", param);
			$("#entryDetailInfo").show(); 
			
		});
		
		
	});
	
	//点击新增按新增字典大类型
	function addDictFuc(){
		$("#dictDetailIframe").show();
		$("#dictDetailIframe").load("${ctx}/dict/addDict.do",function(){
			$("#dictDetailIframe").data("dictBtnFlag","add").dialog("open");
		});
		
	}
	
	function showDetail(dictType,evt){
		var e=(evt)?evt:window.event; //判断浏览器的类型，在基于ie内核的浏览器中的使用cancelBubble
		if (window.event) { 
			e.cancelBubble=true; 
		} else { 
			//e.preventDefault(); //在基于firefox内核的浏览器中支持做法stopPropagation
			e.stopPropagation(); 
		} 
		var param = {"dictType":dictType};
		$("#dictDetailIframe").empty();
		$("#dictDetailIframe").load("${ctx}/dict/addDict.do",param,function(){
			$("#dictDetailIframe").data("dictBtnFlag","show").dialog("open");
		});
		
	}
	
	
	function removeItem(dictType){
		removeDictItem(dictType,function(){
		   	$("#dictListIframe").load("${ctx}/dict/list.do?temp="+new Date().getTime(),$("#dict_info_form").serialize());
		});
	}

	function removeDictItem(dictType,callback){
		if(confirm("确定删除该字典类型吗?")){
			$.post("${ctx}/dict/checkDict.do",{"dictType":dictType},function(result){
				if(result == "success"){
					$.post("${ctx}/dict/removeDict.do",{"dictType":dictType},function(result){
						if(result[0] == "ok"){
							alert("删除成功！");
							callback();
						}else{
							alert(result[1]);
						}
					})
				}else{
					alert("此字典类型下面有字典项，没法被删除！");
				}
			});
		}
	}

</script>

<div class="row">
  <div class="col-xs-12">
    <div class="table-header">
					字典大类列表
					<div class="pull-right tableTools-container"></div>
	</div>
	<div>
		<table id="dictInfoLists"   class="table table-striped table-bordered table-hover" style="table-layout:fixed;">
	    <thead>
		<tr>
		    <th  style="text-align:center;"><b>字典编码</b></th>
			<th  style="text-align:center;"><b>字典描述</b></th>		
			<th  style="text-align:center;"><b>备注</b></th>
			<th  style="text-align:center;"><b>操作</b></th>
		</tr>
		</thead>
		<tbody>
		
		<%-- <c:forEach var="dict" items="${dictList}">
		   <tr>
		   <td>${dict.dictType}</td>
		   <td>
		   <hw:orgName orgId=" ${dict.orgId}"/>
		    </td>
		   <td>${dict.dictDesc}</td>
		   <td>${dict.remark}</td>
		   <td>
		   <div class="hidden-sm hidden-xs action-buttons">
				<a class="green" href="javascript:void(0)" onclick="modifyDictType('${dict.dictType}')" title="修改">
					<i class="ace-icon fa fa-pencil bigger-130"></i>
				</a>
				<a class="red" href="javascript:void(0)" onclick="removeDict('${dict.dictType}')" title="删除">
					<i class="ace-icon fa fa-trash-o bigger-130"></i>
				</a>
			</div>
		   </td>
		   </tr>	
		</c:forEach> --%>
		</tbody>			
	</table>
	</div>			
	</div>
</div>
<div id="entryDetailInfo"></div>
<div id="addEntryInfo"></div>
<div id="dictListIframe"></div>	
<br>
<div id="dictDetailIframe"></div>
